using Microsoft.Build.Framework.XamlTypes;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AvaloniaMaidVSIX.Models
{
    public enum ItemType
    {
        Unknown = 0, File, Folder
    }

    public class ProjectItemInfo
    {
        public string ProjectFullPath { get; set; }
        public string ProjectName { get; set; }
        public string ProjectDirPath { get; set; }
        public string ItemFullPath { get; set; }
        public string ItemShortPath { get; set; }
        public ItemType ItemType { get; set; }
        public ProjectItemInfo()
        {

        }

        public ProjectItemInfo(string projectPath, string itemPath)
        {
            ProjectFullPath = projectPath;
            ProjectName = Path.GetFileNameWithoutExtension(projectPath);
            ProjectDirPath = Path.GetDirectoryName(projectPath);
            ItemFullPath = itemPath;
            ItemShortPath = itemPath.Substring(ProjectDirPath.Length).Trim('\\').Trim('/');

            if (File.Exists(ItemFullPath))
            {
                ItemType = ItemType.File;
            }
            else if (Directory.Exists(ItemFullPath))
            {
                ItemType = ItemType.Folder;
            }
        }

        public override string ToString()
        {
            return $"{ProjectDirPath} {ItemShortPath}";
        }

        public string GetNamespaceName()
        {
            if (ItemType != ItemType.Folder) throw new Exception();

            var str = ProjectName + "." + ItemShortPath.Replace('\\', '.').Replace('/', '.').Trim('.');

            return str;
        }

        public string GetNamespaceName(string rootName)
        {
            if (string.IsNullOrWhiteSpace(rootName)) return GetNamespaceName();
            if (ItemType != ItemType.Folder) throw new Exception();

            var str = rootName + "." + ItemShortPath.Replace('\\', '.').Replace('/', '.').Trim('.');

            return str;
        }

    }
}
